<?php
class wd_facebook_widget extends WP_Widget
{  
    public function wd_facebook_widget()
    {  
      $widgetOptions = array( 'description' => 'Pozwala na wyświetlenie kontenera z treścią i linkiem do profilu Facebook');
      parent::WP_Widget(false, __('WD Facebook'), $widgetOptions);  
    }  
    
    public function form($instance)
    {       
        $formWrapper = '<p><label for="%1$s">%2$s</label><input class="widefat" id="%1$s" name="%3$s" type="text" value="%4$s" /></p>';
        
        $textareaWrapper = '<p><label for="%1$s">%2$s</label><textarea class="widefat" id="%1$s" name="%3$s">%4$s</textarea></p>';
        
        $title = sprintf($formWrapper, $this->get_field_id('title'), __('Title:'), $this->get_field_name('title'), esc_attr($instance['title']));
        
        $content = sprintf($textareaWrapper, $this->get_field_id('content'), __('Content:'), $this->get_field_name('content'), esc_attr($instance['content']));
        
        $link = sprintf($formWrapper, $this->get_field_id('link'), __('Link:'), $this->get_field_name('link'), esc_attr($instance['link']));
              
        print $title.$content.$link;
    }
    
    public function update($new_instance, $old_instance)
    {  
        return $new_instance;  
    }
    
    public function widget($args, $instance)
    {  
        $args['title'] = $instance['title'];  
        
        $args['content'] = $instance['content'];  
        
        $args['link'] = $instance['link'];  
                
        self::display($args['content'], $args['link'],  $args['title']);
    }  
    
    
    public static function display($content, $link, $title = null)
    {       
      wp_enqueue_style('widget-wd-facebook', get_template_directory_uri() .'/css/wd_widget_facebook.css');
      wp_print_styles('widget-wd-facebook');
      
      if(!is_null($title))
      {
        printf('<div class="widget widget_wd_facebook"><div id="band-top"></div><div class="content-wrapper"><h3 class="title">%s</h3>', $title);
      }     
      else
      {
        print '<div class="widget widget_wd_facebook">';
      }
      
      printf('<a class="facebook_image" href="%s"><img src="'. get_template_directory_uri() .'/images/facebook_image.jpeg" /></a><div class="content">%s</div><a class="link" href="%s">więcej</a>', $link, $content, $link);  
      
      if($title != null)
      {
        print '</div><div id="band-bottom"></div></div>';
      }
    }     
}  

register_widget('wd_facebook_widget');  
?>